<template>
  <div class="app-container">
    <search-form v-if="fieldList"
      :fields="fieldList"
      v-show="showSearch"
      @submit="handleQuery"
      @cancel="resetQuery"
    ></search-form>

    <!-- 工具栏 
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['run:'+moduleInfo.code+':remove']"
          >删除</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    -->
    <!-- 表格 -->
    <el-table
      v-loading="loading"
      :data="dataList"
    >
      <el-table-column type="selection" width="55" align="center" />
      <template v-for="(f, i) in fieldList">
        <el-table-column
          :label="f.label"
          align="center"
          :prop="f.code"
          :key="i"
          v-if="f.list == 'Y' && f.type == 'checkbox'"
        >
          <template slot-scope="scope">
            {{ dictLabel(f.code, scope.row[f.code])}}
          </template>
        </el-table-column>
        <el-table-column
          :label="f.label"
          align="center"
          :prop="f.code"
          :key="i"
          v-else-if="f.list == 'Y' && f.type == 'radio'"
        >
          <template slot-scope="scope">
            {{ dictLabel(f.code, scope.row[f.code])}}
          </template>
        </el-table-column>
        <el-table-column
          :label="f.label"
          align="center"
          :prop="f.code"
          :key="i"
          v-else-if="f.list == 'Y' && f.type == 'date'"
        >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row[f.code], '{y}-{m}-{d}') }}</span>
        </template>
        </el-table-column>
        <el-table-column
          :label="f.label"
          align="center"
          :prop="f.code"
          :key="i"
          v-else-if="f.list == 'Y' && f.type == 'datetime'"
        >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row[f.code]) }}</span>
        </template>
        </el-table-column>        
      <el-table-column  v-else-if="f.list == 'Y' && f.type == 'images'"        
          :label="f.label"
          align="center"
          :prop="f.code"
          :key="i" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row[f.code]" :width="50" :height="50"/>
        </template>
      </el-table-column>
        <el-table-column
          :label="f.label"
          align="center"
          :prop="f.code"
          :key="i"
          v-else-if="f.list == 'Y'"
        />
      </template>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button 
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            >查看</el-button
          >
          <el-button v-if="scope.row.check_status == '1'"
            size="mini"
            type="text"
            icon="el-icon-check"
            @click="handleCheck(scope.row)"
            v-hasPermi="['run:'+moduleInfo.code+':check']"
          >审批</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="pager.page"
      :limit.sync="pager.limit"
      @pagination="getList"
    />
    
    <!-- 审批 -->
    <check-dialog :applyData="apply" model="asset_purchase" @cancel="applyCancel" @success="applySuccess" />
  </div>
</template>

<script>
import { apiGet } from "@/api/openapi";
import ListMixin from "./list"
import CheckDialog from "@/components/ApplyDialog/check";
import FormDialog from "./form"
import SearchForm from "./search"

export default {
  name: "RunFlow",
  components: {
    CheckDialog, FormDialog, SearchForm
  },
  dicts: [],
  mixins: [ListMixin],
  data() {
    return {
    };
  },
  methods: {    
    
        /** 查询列表 */
        getList() {
            this.loading = true;
            
            let modelCode = this.moduleInfo['api_model'];
            let params = {"@pager":this.pager};
            let p =  { ...this.queryParams, '@alias':"t", "@exp": this.queryExp };
            if (this.moduleInfo['api_ds'] && this.moduleInfo['api_ds'].trim()) {
                let ds = JSON.parse(this.moduleInfo['api_ds']);
                if(ds[modelCode]){
                    //一般是默认查询条件
                    for(var k in ds[modelCode]){
                        p[k] = ds[modelCode][k];
                    }
                    delete ds[modelCode];
                }
                params = Object.assign(params, ds);
            }
            params[modelCode] = p; 
            params[modelCode]['apply_status'] = '2';
            params['asset_flow'] = {
              "@column":"id:flow_id",
              "check_user_id": this.userId,
              "check_status": '1',
              "ignore_flag": '0',
              "@alias":"_flow",
              "@join":"_flow.data_id=t.id AND _flow.flow_model='"+modelCode+"'"
            };
            apiGet(params).then(response => {
                this.dataList = response.data.rows;
                this.total = response.data.total;
                this.loading = false;
            });
        },
        handleCheck(row) {
          this.apply = {
            "data_id":row.id,
            "flow_id":row.flow_id,
            "flow_model": this.moduleInfo['api_model'],
            "title": "审批 " + this.moduleInfo['name'],
            "reason": row.reason
          }
        }
  }
};
</script>
<!--
列表字段的处理逻辑如下：
1、按排序展示字段，可设置列表不展示，具体内容按类型进行格式化
2、普通内容原样展示
3、日期和日期时间自动格式化为 yyyy-MM-dd和yyyy-MM-dd hh:mm:ss
4、支持图片预览
5、支持字典转义
-->
